package com.ut.demo.slice;

import com.ut.demo.ResourceTable;
import com.ut.demo.util.LogUtil;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.animation.Animator;
import ohos.agp.animation.AnimatorGroup;
import ohos.agp.animation.AnimatorValue;
import ohos.agp.components.Component;

public class MainAbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        findComponentById(ResourceTable.Id_test).setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                animationTest();
            }
        });
    }

    private void animationTest(){
        AnimatorValue animator_a = new AnimatorValue();
        animator_a.setCurveType(Animator.CurveType.LINEAR);
        animator_a.setDuration(1000);
        animator_a.setLoopedCount(2);
        animator_a.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() {
            @Override
            public void onUpdate(AnimatorValue animatorValue, float v) {
                LogUtil.i("animator value: %f", v);
            }
        });
        AnimatorValue animator_b = new AnimatorValue();
        animator_b.setCurveType(Animator.CurveType.LINEAR);
        animator_b.setDuration(1000);
        animator_b.setLoopedCount(2);
        animator_b.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() {
            @Override
            public void onUpdate(AnimatorValue animatorValue, float v) {
                LogUtil.i("animator value: %f", v);
            }
        });
        AnimatorValue animator_c = new AnimatorValue();
        animator_c.setCurveType(Animator.CurveType.LINEAR);
        animator_c.setDuration(1000);
        animator_c.setLoopedCount(2);
        animator_c.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() {
            @Override
            public void onUpdate(AnimatorValue animatorValue, float v) {
                LogUtil.i("animator value: %f", v);
            }
        });
        AnimatorValue animator_d = new AnimatorValue();
        animator_d.setCurveType(Animator.CurveType.LINEAR);
        animator_d.setDuration(1000);
        animator_d.setLoopedCount(2);
        animator_d.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() {
            @Override
            public void onUpdate(AnimatorValue animatorValue, float v) {
                LogUtil.i("animator value: %f", v);
            }
        });
        AnimatorValue animator_e = new AnimatorValue();
        animator_e.setCurveType(Animator.CurveType.LINEAR);
        animator_e.setDuration(1000);
        animator_e.setLoopedCount(2);
        animator_e.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() {
            @Override
            public void onUpdate(AnimatorValue animatorValue, float v) {
                LogUtil.i("animator value: %f", v);
            }
        });
        AnimatorGroup animatorGroup = new AnimatorGroup();
        animatorGroup.runParallel(animator_a, animator_b, animator_c, animator_d, animator_e);
        animatorGroup.start();
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
